package com.vayne.injectdemo;

import com.vayne.bean.Course;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.inject.Inject;

/**
 * 依赖查找解析流程 {@link DefaultListableBeanFactory#resolveDependency}
 *
 * @author xuerui.zhang
 * @since 2020/4/15 上午11:34
 */
public class AnnotationDependencyResolveDemo {

    //@Autowired
    @Inject
    private Course category;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(AnnotationDependencyResolveDemo.class);

        XmlBeanDefinitionReader beanDefinition = new XmlBeanDefinitionReader(applicationContext);
        String path = "classpath:/dependency_lookup_config.xml";
        beanDefinition.loadBeanDefinitions(path);

        applicationContext.refresh();
        AnnotationDependencyResolveDemo demo = applicationContext.getBean(AnnotationDependencyResolveDemo.class);
        System.out.println("Autowired Category：" + demo.category);
        applicationContext.close();
    }
}
